package com.service.machine;

import com.common.ErrorCodeEnum;
import com.common.emums.DataStatus;
import com.common.exception.BusinessException;
import com.common.utils.StringUtils;
import com.core.springSecurity.common.SecurityUtils;

import com.dao.primary.machine.MachineModelInfoMapper;
import com.github.pagehelper.Page;
import com.model.domain.machine.GetMachineModelInfoDO;
import com.model.pojo.machine.MachineModelInfo;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author: zql
 * @Description: 农机型号信息服务
 * @Data: 2024-02-28
 */
@Slf4j
@Service
@Data
public class MachineModelInfoService {
    private final MachineModelInfoMapper machineModelInfoMapper;
    public List<MachineModelInfo> getPageList(GetMachineModelInfoDO getMachineModelInfoDO){
        PageHelper.clearPage();
        PageHelper.startPage(getMachineModelInfoDO.getPage(),getMachineModelInfoDO.getPageSize(),getMachineModelInfoDO.getSortRow()+getMachineModelInfoDO.getSortOrder());
        return machineModelInfoMapper.selectList(getMachineModelInfoDO);
    }
    public int save(MachineModelInfo info){
        info.setCreatedTime(new Date());
        return machineModelInfoMapper.insertSelective(info);
    }
    public int update(MachineModelInfo info){
        info.setLastModifiedTime(new Date());
        return machineModelInfoMapper.updateByPrimaryKeySelective(info);
    }

    public MachineModelInfo getById(Long modelId){
        return machineModelInfoMapper.selectByPrimaryKey(modelId);
    }
}
